package com.mlc.mlcitems.damage;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

import static com.mlc.mlcitems.Mlcitems.instance;

public class arrowdamage {
    public static void damageone(Player player, Entity entity , int damage,double range){
        Bukkit.getScheduler().scheduleSyncRepeatingTask(instance,()->{
            if (entity.isDead() || !entity.isValid()) {
                return;
            }

            Location location = entity.getLocation();

            for (Entity entity1 : entity.getWorld().getNearbyEntities(
                    location, range, range, range)) {
                if (entity1 != entity && entity1 !=player && entity1 instanceof LivingEntity livingEntity) {
                    livingEntity.damage(damage,player);
                    entity.remove();
                }
            }
        },0L,0L);
    }

    public static void damagethrough(Player player, Entity entity ,int damage,double range){
        Bukkit.getScheduler().scheduleSyncRepeatingTask(instance,()->{
            if (entity.isDead() || !entity.isValid()) {
                return;
            }

            Location location = entity.getLocation();

            for (Entity entity1 : entity.getWorld().getNearbyEntities(
                    location, range, range, range)) {
                if (entity1 != entity && entity1 !=player && entity1 instanceof LivingEntity livingEntity) {
                    livingEntity.damage(damage,player);
                }
            }
        },0L,0L);
    }

    public static void damageaoe(Player player, Entity entity ,double damage,double range){

        Bukkit.getScheduler().scheduleSyncRepeatingTask(instance,()->{
            if (entity.isDead() || !entity.isValid()) {
                return;
            }
            Location location = entity.getLocation();

            for (Entity entity1 : entity.getWorld().getNearbyEntities(
                    location, range, range, range)) {
                if (entity1 != entity && entity1 !=player && entity1 instanceof LivingEntity livingEntity) {
                    livingEntity.damage(damage,player);
                }
            }
        },0L,0L);
    }
}
